﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FileMover.SharedControls
{
    public partial class AddActionForm : Form
    {
        public AddActionForm()
        {
            InitializeComponent();
        }

        List<FileMover.Service.IFactory> _entries;
        private void AddActionForm_Load(object sender, EventArgs e)
        {
            _entries = new List<FileMover.Service.IFactory>();
            foreach (var fact in FileMover.Service.Registry.Filters.GetFactories())
                _entries.Add(fact);

            foreach (var act in FileMover.Service.Registry.Actions.GetFactories())
                _entries.Add(act);

            listBox1.DataSource = _entries;
        }

        private void listBox1_Format(object sender, ListControlConvertEventArgs e)
        {
            var factory = e.ListItem as FileMover.Service.IFactory;
            e.Value = factory.ToString();
        }

        public FileMover.Service.IFactory SelectedFactory
        {
            get
            {
                if (listBox1.SelectedItem == null) return null;
                return listBox1.SelectedItem as FileMover.Service.IFactory;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
